import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
import { LayerBase } from './LayerBase';
import { UserInfo } from './UserInfo';
import { PetItem } from './PetItem';
import { Pet } from './Pet';
const { ccclass, property } = _decorator;

@ccclass('PetPanel')
export class PetPanel extends LayerBase {
    
    @property(Node)
    hasPetContent:Node;
    @property(Node)
    notHasPetContent: Node;
    @property(Prefab)
    petItemPre:Prefab;

    init(somedData?: any): void {
        this.hasPetContent.removeAllChildren();
        this.notHasPetContent.removeAllChildren();

        UserInfo.hasPetDic.getValueList().forEach((ele) => {
            console.log("ele",ele)
                let pre = instantiate(this.petItemPre);
                pre.setParent(this.hasPetContent);
                pre.getComponent(PetItem).init(ele,true)
        })

        UserInfo.petCongfiDic.getValueList().forEach((ele) => {
            let tempClass = new Pet();
            tempClass.initData(ele);
            tempClass.petType=ele.petType;
            let pre = instantiate(this.petItemPre);
            pre.setParent(this.notHasPetContent);
            pre.getComponent(PetItem).init(tempClass, false)
        })
    }
}


